package tt.dz.order.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

/**
 * @Title 订单系统常量类
 * @author zhoutian
 * @date 2015-11-26
 */
public class OrderConstant {
	/** 15分钟的毫秒整数值 */
	public static final int Fifteen_MINUTE_INT = 1000 * 60 * 15;

	/** 电桩 自己的运营商编号 */
	public static final String DZMerchantCode = OrderAppConfig.GET().getMerchantCode();
	/** 模拟空的第三方实时支付方式的外部交易流水号，29位0 */
	public static final String NULL_THIRDIMMEDIATELY_TRADE_NO = "0000000000000000000000000000";
	/** 模拟空的第三方实时支付方式外部交易结果 */
	public static final String NULL_THIRDIMMEDIATELY_TRADE_STATUS = "TRADE_STATUS_SUCCESS";

	/**
	 * 服务枚举
	 * 
	 * @author zhoutian
	 */
	public static enum OrderServiceEnum {
		Charge("100", "充电"), ChargeService("100001", "充电服务"), CollectingElectricityFee("100002",
				"代收电费服务"), ChargeAppointment("100003", "充电预约服务"), Appointment("200",
						"预约"), ChargeAppointmentRefund("200002", "充电预约退款服务");

		private String value = null;
		private String desc = null;

		private OrderServiceEnum(String v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		public static String getDesc(String value) {
			if (value == null)
				return null;
			for (OrderServiceEnum se : OrderServiceEnum.values()) {
				if (se.value.equals(value)) {
					return se.desc();
				}
			}
			return null;
		}
	}

	/**
	 * 
	 * 
	 * @name 订单类型
	 * @author Anson
	 * @version 1.0
	 * @summary
	 * @desc
	 *
	 */
	public static enum OrderType {
		/**
		 * 先消费形成订单
		 */
		AFTER_PAYMENT(0, "后付款"),
		/**
		 * 先存一定的金额，后消费，最后平衡差额
		 */
		ADVANCE_PAYMENT(1, "预付款");

		private int value = 0;
		private String desc = null;

		private OrderType(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		/**
		 * 获取枚举对象
		 * 
		 * @author Anson
		 * @createDate 2016年4月27日
		 * @desc 根据传入的value
		 * @param value
		 * @return OrderType
		 */
		public static final OrderType indexOf(Integer value) {
			for (OrderType v : OrderType.values()) {
				if (v.value() == value) {
					return v;
				}
			}
			return null;
		}
	}

	public static enum UserType {
		persnal_user(0, "个人客户"), enterprise_user(1, "企业客户"), unifyPay_user(2, "支持统付的个人客户"), offline_customer(3,
				"现金卡用户");

		private int value = 0;
		private String desc = null;

		private UserType(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		/**
		 * 获取枚举对象
		 * 
		 * @author Anson
		 * @createDate 2016年4月27日
		 * @desc 根据传入的value
		 * @param value
		 * @return CardType
		 */
		public static final UserType indexOf(Integer value) {
			for (UserType v : UserType.values()) {
				if (v.value() == value) {
					return v;
				}
			}
			return null;
		}
	}

	/**
	 * 卡类型 08 虚拟，06 实体卡 ，07 身份识别卡
	 */
	public static enum CardType {
		ONLINE_CARD("08", "08 虚拟"), OFFLINE_CARD("06", "06 实体卡"), IDENTITY_CARD("07", "07 身份识别卡");

		private String value;
		private String desc;

		private CardType(String value, String desc) {
			this.value = value;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String toString() {
			return this.value + ":" + this.desc;
		}

		public String getDesc() {
			return desc;
		}

		/**
		 * 获取枚举对象
		 * 
		 * @author Anson
		 * @createDate 2016年4月27日
		 * @desc 根据传入的value
		 * @param value
		 * @return CardType
		 */
		public static final CardType indexOf(String value) {
			for (CardType v : CardType.values()) {
				if (v.value().equals(value)) {
					return v;
				}
			}
			return null;
		}
	}

	public static enum OrderStatus {
		unPay(0, "未支付"), paying(1, "正在支付"), unAudit(2, "未审核"), auditing(3, "正在审核"), confirmed(4, "已确认"), stocking(5,
				"备货中"), delivered(6, "已发货"), payedDone(7, "已支付，已完成"), canceledDone(8, "已取消，已完成"), overdueDone(9,
						"已超期，已完成");// 充电预约订单超过可取消的期限，不能退款

		private int value = 0;
		private String desc = null;

		private OrderStatus(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		public static String getDesc(Integer value) {
			OrderStatus status = getStatusByValue(value);
			return status == null ? null : status.desc;
		}

		/**
		 * 根据当前value值获取当前有效订单状态
		 * 
		 * @param value
		 * @return
		 */
		public static OrderStatus getStatusByValue(Integer value) {
			if (value == null) {
				return null;
			}
			for (OrderStatus se : OrderStatus.values()) {
				if (se.value == value) {
					return se;
				}
			}
			return null;
		}
	}

	public static enum ProviderServiceStatus {
		disable(0, "停用"), enable(1, "启用");

		private int value = 0;
		private String desc = null;

		private ProviderServiceStatus(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 支付方式
	 */
	public static enum OrderPayWay {
		thirdImmediately(1, "第三方实时支付"), unify(2, "统付"), enterprise(3, "企业支付"), electronicPurse(4,
				"电子钱包支付"), substitute(5, "代付"), offLineCard(6, "线下卡支付"), CASH_PAY(7, "现金支付"), OUT_OFFLINE_CARD_PAY(8,
						"外部现金卡(外部线下卡)"), IMPREST_PAY(9, "预付款支付"), FREE_PAY(10, "免收费");

		private int value = 0;
		private String desc = null;

		private OrderPayWay(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		public static String getDesc(Integer value) {
			if (value == null)
				return null;
			OrderPayWay payWay = get(value);
			return payWay == null ? null : payWay.desc;
		}

		public static OrderPayWay get(Integer value) {
			if (value == null)
				return null;
			for (OrderPayWay se : OrderPayWay.values()) {
				if (se.value == value) {
					return se;
				}
			}
			return null;
		}
	}

	/**
	 * 支付状态
	 */
	public static enum OrderPayStatus {
		payed(1, "已支付/支付成功"), unpay(2, "待支付"), paying(3, "支付中"), payFail(4, "支付失败"), payTimeOut(5, "支付超时");

		private int value = 0;
		private String desc = null;

		private OrderPayStatus(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 支付渠道编码
	 */
	public static enum OrderPayChannelCode {
		alipay("ALI", "支付宝"), weixinpay("WEIXIN", "微信支付"), youbeipay("UBEE", "有贝先付");

		private String value = "alipay";
		private String desc = null;

		private OrderPayChannelCode(String v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		public static String getDesc(String value) {
			if (value == null)
				return null;
			OrderPayChannelCode payWay = get(value);
			return payWay == null ? null : payWay.desc;
		}

		public static OrderPayChannelCode get(String value) {
			if (value == null)
				return null;
			for (OrderPayChannelCode se : OrderPayChannelCode.values()) {
				if (se.value.equals(value)) {
					return se;
				}
			}
			return null;
		}
	}

	/**
	 * 订单发送台帐状态
	 */
	public static enum AccountingStatus {
		needSendNew(0, "支付完成，需要发送"), needSendAgain(1, "发送返回失败，需要再次发送"), sending(2, "正在发送"), success(3, "发送并返回成功");

		private int value = 0;
		private String desc = null;

		private AccountingStatus(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 发送充电预约退款订单的状态
	 */
	public static enum SendRefundStatus {
		needSendNew(0, "新生成，需要发送"), needSendAgain(1, "返回失败，需要再次发送"), sending(2, "正在发送"), success(3, "成功返回并处理成功");

		private int value = 0;
		private String desc = null;

		private SendRefundStatus(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 是否分润标志
	 */
	public static enum DividedFlag {
		no(0, "否"), yes(1, "是");

		private int value = 0;
		private String desc = null;

		private DividedFlag(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 支付宝支付交易状态码
	 */
	public static enum AliPayTradeStatus {
		TRADE_FINISHED("TRADE_FINISHED", "交易成功"), TRADE_SUCCESS("TRADE_SUCCESS",
				"支付成功"), WAIT_BUYER_PAY("WAIT_BUYER_PAY", "交易创建"), TRADE_CLOSED("TRADE_CLOSED", "交易关闭");

		private String value = null;
		private String desc = null;

		private AliPayTradeStatus(String v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 业务系统编码
	 */
	public static enum BizSystemCode {
		MainServer("101", "主服务器"), OrderServer("102", "订单服务器"), OMS("103", "综合运营管理服务器"), DzApp("104",
				"电桩APP"), LeTV("201", "乐视APP"), Dz("000", "充电桩"), DzWeiXin("114", "电桩微信"), HuaTiWeiXin("124", "华体微信");

		private String value = null;
		private String desc = null;

		private BizSystemCode(String v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 
	 * 
	 * @name 预付款支付阶段
	 * @author Anson
	 * @version 1.0
	 * @summary
	 * @desc
	 *
	 */
	public static enum AdvancePaymentStage {

		ADVANCE(1, "预付款"), INCOME(2, "收入"), BALANCE_ALLOWANCE(3, "差额平衡");

		private int value = 0;
		private String desc = null;

		private AdvancePaymentStage(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		/**
		 * 根据值状态获取枚举
		 * 
		 * @param value
		 * @return
		 */
		public static final AdvancePaymentStage valueOfByStr(String value) {
			if (StringUtils.isEmpty(value) || !NumberUtils.isDigits(value)) {
				return null;
			}
			int type = NumberUtils.createInteger(value);
			return valueOfByInt(type);
		}

		/**
		 * 根据值状态获取枚举
		 * 
		 * @param value
		 * @return
		 */
		public static final AdvancePaymentStage valueOfByInt(int value) {
			for (AdvancePaymentStage stage : AdvancePaymentStage.values()) {
				if (stage.value == value) {
					return stage;
				}
			}
			return null;
		}

		/**
		 * 获取描述
		 * 
		 * @param value
		 * @return
		 */
		public static final String getDesc(String value) {
			AdvancePaymentStage stage = valueOfByStr(value);
			return stage == null ? "" : stage.desc;
		}

		/**
		 * 判断当前是否是预付款阶段
		 * 
		 * @return
		 */
		public static final boolean isAdvance(int stage) {
			return stage == ADVANCE.value;
		}

		/**
		 * 判断当前是否是预收入阶段
		 * 
		 * @return
		 */
		public static final boolean isInCome(int stage) {
			return stage == INCOME.value;
		}

		/**
		 * 判断当前是否是差额平衡阶段
		 * 
		 * @return
		 */
		public static final boolean isBalanceAllowance(int stage) {
			return stage == BALANCE_ALLOWANCE.value;
		}

		/**
		 * 判断当前是否是预付款阶段
		 * 
		 * @return
		 */
		public static final boolean isAdvance(AdvancePaymentStage stage) {
			return stage == ADVANCE;
		}

		/**
		 * 判断当前是否是预收入阶段
		 * 
		 * @return
		 */
		public static final boolean isInCome(AdvancePaymentStage stage) {
			return stage == INCOME;
		}

		/**
		 * 判断当前是否是差额平衡阶段
		 * 
		 * @return
		 */
		public static final boolean isBalanceAllowance(AdvancePaymentStage stage) {
			return stage == BALANCE_ALLOWANCE;
		}
	}

	/**
	 * 订单系统运营管理操作员登录结果
	 */
	public static enum LoginForOperResult {
		fail(0, "失败"), success(1, "成功");

		private int value = 0;
		private String desc = null;

		private LoginForOperResult(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 运营商经营方式
	 */
	public static enum MerchantOperationMode {
		cooperative(0, "合作经营"), principal(1, "自营");

		private int value = 0;
		private String desc = null;

		private MerchantOperationMode(int v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public int value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * CRUD操作枚举
	 */
	public static enum CRUDCode {
		Create("C", "新增"), Retrieve("R", "读取"), Update("U", "修改"), Delete("D", "删除");

		private String value = null;
		private String desc = null;

		private CRUDCode(String v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}
	}

	/**
	 * 业务类型：0 业务， 1 job，2 rpc，9 其它
	 */
	public static enum BizType {
		/**
		 * 业务
		 */
		BUSINESS("0", "业务"),
		/**
		 * JOB
		 */
		JOB("1", "JOB"),
		/**
		 * RPC
		 */
		RPC("2", "RPC"),
		/**
		 * 其它
		 */
		OTHER("9", "其它");

		private String value;
		private String desc;

		private BizType(String value, String desc) {
			this.value = value;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String toString() {
			return this.value;
		}

		public String getDesc() {
			return desc;
		}
	}

	/**
	 * 
	 * 
	 * @name 运行模式
	 * @author Anson
	 * @version 1.0
	 * @summary debug,调试;test,测试;release:正式版
	 * @desc
	 *
	 */
	public static enum RuntimeMode {
		/**
		 * 业务
		 */
		DEBUG("debug", "调试"),
		/**
		 * JOB
		 */
		TEST("test", "测试"),
		/**
		 * Z
		 */
		RELEASE("release", "正式版");

		private String value;
		private String desc;

		private RuntimeMode(String value, String desc) {
			this.value = value;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String toString() {
			return this.value;
		}

		public String getDesc() {
			return desc;
		}

		public static RuntimeMode indexOfByStr(String value) {
			for (RuntimeMode mode : RuntimeMode.values()) {
				if (mode.value.equals(value)) {
					return mode;
				}
			}
			return null;
		}

		/**
		 * 当前运行模式
		 * 
		 * @return
		 */
		public static RuntimeMode curMode() {
			return RuntimeMode.indexOfByStr(OrderAppConfig.GET().getRuntimeMode());
		}
	}
}